package org.testmyapp.listeners;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.testmyapp.entities.AccountingMedical;
import org.testmyapp.persistence.BusinessObjectPersistenceProvider;
import org.testmyapp.session.SessionForUser;

@Named(value="startAccountingMedical")
@ApplicationScoped
public class AccountingMedicalStartListener implements ExecutionListener {
	
	@Inject
	private SessionForUser session;
	
	@Inject
	private BusinessObjectPersistenceProvider bopp;

	public void notify(DelegateExecution execution) throws Exception {
		String processInstanceId = execution.getProcessInstanceId();
		AccountingMedical accMedicalInstance = new AccountingMedical();
		accMedicalInstance.setProcessInstanceId(processInstanceId);
		Integer keyForProcessEntity = bopp.getKeyForProcessEntity(AccountingMedical.tableName);
		accMedicalInstance.setId(keyForProcessEntity);
		execution.setVariable("accountingMedical", accMedicalInstance);
	}

}
